<?php
/**
 * Created by PhpStorm.
 * User: wangwenfan
 * Date: 2018/8/28
 * Time: 13:42.
 */

namespace App\Admin\Controllers;

use App\Models\Base\LogDropLevel;
use App\Models\Base\ServerList;
use Encore\Admin\Facades\Admin;
use Encore\Admin\Grid;
use Encore\Admin\Layout\Content;

class LevelWashController extends Controller
{
    public function index()
    {
        return Admin::content(function (Content $content) {
            $content->header(trans('game.data_statistic'));
            $content->description(trans('game.grade_loss_statistics'));
            $content->body($this->grid());
        });
    }

    protected function grid()
    {
        return Admin::grid(LogDropLevel::class, function (Grid $grid) {
            $grid->server()->name(trans('game.server_name'));
            $grid->level(trans('game.level'))->sortable();
            $grid->role_number(trans('game.number'))->sortable();
            $grid->wastage_rate('流失率')->display(function ($rate) {
                return floatPercent($rate);
            });
            $grid->level_proportion(trans('game.level_weight'))->display(function ($prop) {
                return floatPercent($prop);
            });
            $grid->total_level_proportion(trans('game.level_sum_weight'))->display(function ($tot_prop) {
                return floatPercent($tot_prop);
            });
            $grid->three_not_online_number(trans('game.three_day_not_online'));
            $grid->three_wastage_rate(trans('game.three_days_loss'))->display(function ($three_rate) {
                return floatPercent($three_rate);
            });
            $grid->one_day_not_online(trans('game.one_day_not_online'));
            $grid->one_day_wastage_rate(trans('game.one_day_wastage_rate'))->display(function ($one_rate) {
                return floatPercent($one_rate);
            });
            $grid->disableActions();
            $grid->disableCreateButton();

            $grid->filter(function ($filter) {
                // 去掉默认的id过滤器
                $filter->disableIdFilter();
                $filter->equal('server_id', trans('game.server_name'))->select(ServerList::all()->pluck('name', 'server_id'));
            });
        });
    }
}
